/**
 * @author molin
 * created on 2017/5/15.
 */
(function () {
    'use strict';

    angular.module('BlurAdmin.pages.user.userPage')
        .controller('userPageCtrl', userPageCtrl);

    function userPageCtrl($scope, $log, $state, $http, ProfileService, ErrorParserService) {
        var ctrl = $scope;

        //正在加载标志
        ctrl.isLoading = true;
        //加载失败标志
        ctrl.isFailed = false;
        //当前显示
        ctrl.displayed = [];
        //单页数量
        ctrl.itemsByPage = 20;
        //总数量
        ctrl.totalItemCount = 0;

        ctrl.callServer = function callServer(tableState) {
            ctrl.tableState = tableState;
            ctrl.getData();
        };

        ctrl.getData = function (reset_page) {
            console.info("getData...");
            ctrl.isLoading = true;
            if(reset_page)
            {
                ctrl.tableState.pagination.start = 0;
                ctrl.searchArgs.selectGroup = ctrl.filterArgs.selectGroup;
                ctrl.searchArgs.name = ctrl.filterArgs.name;
                ctrl.searchArgs.sectionName = ctrl.filterArgs.sectionName;
            }
            var pagination = ctrl.tableState.pagination;
            var sort = ctrl.tableState.sort;
            var queryArgs = {

            };

            $http.get(ProfileService.SERVICE_USER_QUERY, queryArgs).then(function (response) {
                $log.info("查询成功...");
                /*var tmp_displayed = response.data.lessons;
                parseDisplayed(tmp_displayed, queryArgs.start);
                ctrl.totalItemCount = response.data.totalCount;
                pagination.numberOfPages = getPageCount(ctrl.totalItemCount);
                ctrl.isLoading = false;
                ctrl.isFailed = false;*/
            }).catch(function (response) {
                $log.info('查询失败...');
                /*ctrl.displayed = [];
                pagination.numberOfPages = 1;
                ctrl.isLoading = false;
                ctrl.isFailed = true;*/
            });

        };
    }
})();